require(['bbcare'], function ($bb) {
    var URL = $bb.baseUrl("followup");

    // URL = 'http://192.168.3.138:8090'

    var vm = new Vue({
        el: '#root',
        data: {
            search: {
                name: '',
                phone: '',
                status: null,
                type: null,
                loading: false
            },
            table: {
                data: [],
                total: 0,
                current: 1,
                pageSize: 10,
                loading: false
            },
        },
        created: function() {
            this.getTableData()
        },
        methods: {
            handleReset: function () {
                this.search.name = ''
                this.search.phone = ''
                this.search.status = null
                this.search.type = null
                this.getTableData()
            },
            /**
             * 改变当前得页码
             * @param {*} current 
             */
             handleChangePage: function(current) {
                this.table.current = current
                this.getTableData()
            },
            /**
             * 判断当前预约状态
             */
             judgeType: function (type) {
                type = String(type)
                switch(type) {
                    case '1': 
                    return '诊后指导'
                    case '2':
                    return '下次检查提醒'
                    case '3': 
                    return '评测报告'
                    case '4': 
                    return '科室宣教'
                    case '5': 
                    return '预约确认通知'
                    case '6':
                    return '预约成功通知'
                    case '7': 
                    return '发奶通知'
                }
            },
            /**
             * 点击查询
             */
            handleSearch: function() {
                this.search.loading = true
                this.getTableData()
            },
            /**
             * 获取列表数据
             */
            getTableData: function () {
                var that = this
                this.table.loading = true
                $bb.ajax({
                    url: URL + 'followup/message/notify/record/listPage',
                    dataType: 'json',
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify({
                        currentPage: this.table.current,
                        pageSize: this.table.pageSize,
                        phone: this.search.phone,
                        userName: this.search.name,
                        type: this.search.type,
                        status: this.search.status
                    }),
                    success: function (res) {
                        if (!res.success) that.$message.error('请求错误，请重新尝试!!!')
                        res.data.data.forEach(function (item, index) {
                            item.No = (that.table.current - 1) * 10 + index + 1
                        })
                        that.table.data = res.data.data
                        that.table.total = res.data.count
                        that.search.loading = false
                        that.table.loading = false
                        that.toTop()
                    }
                })
            },
            toTop: function () {
                var dom = document.getElementById('content-main')
                dom.scrollTo(0, 0)
            }
        }
    })
})  